
/**   
  * 工具:求两个正数之积
  *
  * author Tino
 */
 jQuery.multiply = function (a,b) {
 
	if((Number(a)+"")=="NaN"||(Number(a)+"")=="NaN"){
		return 0;
	}
	
	var n = 0,numbera = Number(a),numberb = Number(b),a=a+"",b=b+"";
	
	var indexa = a.indexOf(".");
	var lengtha = a.length;
	if(indexa != -1){
		n+= lengtha-indexa-1;
		var stra = a.substring(0,indexa)+a.substring(indexa+1,lengtha)
		numbera = Number(stra);
	}
	
	var indexb = b.indexOf(".");
	var lengthb = b.length;
	if(indexb != -1){
		n+= lengthb-indexb-1;
		var strb = b.substring(0,indexb)+b.substring(indexb+1,lengthb)
		numberb = Number(strb);
	}
	
	var multiply = (numbera*numberb);
	multiply+="";
	var lengthm = multiply.length;
	if(n==0){
		return multiply;
	}else if(lengthm>n){
		var ra = multiply.substring(0,lengthm-n);
		var rb = multiply.substring(lengthm-n,lengthm);
		if(rb.length>2){
			var rba = rb.substring(0,2);
			var rbb = rb.substring(2,3);
			if(Number(rbb)>=5){
				rba = Number(rba)+1;
			}
			if(rba.length>2){
				rb = '00';
				ra = Number(ra)+1;
			}else if(rba.length==2){
				 rb = rba;
			}else {
				rb = '0'+rba
			}
		}
		return ra+"."+rb;
	}else{
		var temp = "";
		for(var i = 0;i<lengthm-n;i++){
			temp+="0";
		}
		return "0."+temp+multiply;
	}
};

/**   
  * 工具:求两个正数之和
  *
  * author Tino
 */
 jQuery.sum = function (a,b) {
 
  	if((Number(a)+"")=="NaN"||(Number(a)+"")=="NaN"){
		return 0;
	}
	
	var n = 0,na = 0,nb = 0,numbera = Number(a),numberb = Number(b),a=a+"",b=b+"";
	
	var indexa = a.indexOf(".");
	var lengtha = a.length;
	var stra = a;
	if(indexa != -1){
		na = lengtha-indexa-1;
		stra = a.substring(0,indexa)+a.substring(indexa+1,lengtha)
	}
	
	var indexb = b.indexOf(".");
	var lengthb = b.length;
	var strb = b;
	if(indexb != -1){
		nb = lengthb-indexb-1;
		strb = b.substring(0,indexb)+b.substring(indexb+1,lengthb)
	}
	
	if(na>0&&nb>0){
		if(na>=nb){
			n = na;
			numbera = Number(stra);
			var temp = "";
			for(var i = 0;i<na-nb;i++){
				temp+="0";
			}
			numberb = Number(strb+temp);
		}else if(na<nb){
			n = nb;
			numberb = Number(strb);
			var temp = "";
			for(var i = 0;i<nb-na;i++){
				temp+="0";
			}
			numbera = Number(stra+temp);
		}
	}else if(na>0){
		n = na;
		numbera = Number(stra);
		var temp = "";
		for(var i = 0;i<na;i++){
			temp+="0";
		}
		numberb = Number(strb+temp);
	}else if(nb>0){
		n = nb;
		numberb = Number(strb);
		var temp = "";
		for(var i = 0;i<nb;i++){
			temp+="0";
		}
		numbera = Number(stra+temp);
	}else{
		numbera = Number(stra);
		numberb = Number(strb);
	}
	
	var sum = numbera+numberb;
	sum+="";
	var lengthm = sum.length;
	if(n==0){
		return sum;
	}else if(lengthm>n){
		return sum.substring(0,lengthm-n)+"."+sum.substring(lengthm-n,lengthm);
	}else{
		var temp = "";
		for(var i = 0;i<lengthm-n;i++){
			temp+="0";
		}
		return "0."+temp+sum;
	}
 };

/**   
  * 工具:求两个正数数之差，最多两位小数，小数点第三位四舍五入
  *
  * author Tino
 */
 jQuery.reduce = function (a,b) {
	if((Number(a)+"")=="NaN"||(Number(a)+"")=="NaN"){
		return 0;
	}
	
	var n = 0,na = 0,nb = 0,numbera = Number(a),numberb = Number(b),a=a+"",b=b+"";
	
	var indexa = a.indexOf(".");
	var lengtha = a.length;
	var stra = a;
	if(indexa != -1){
		na = lengtha-indexa-1;
		
		var ra = a.substring(0,indexa);
		var rb = a.substring(indexa+1,lengtha);
		
		if(na>2){
			var rba = rb.substring(0,2);
			var rbb = rb.substring(2,3);
			if(Number(rbb)>=5){
				rba = Number(rba)+1;
			}
			if(rba.length>2){
				rb = '00';
				ra = Number(ra)+1;
			}else if(rba.length==2){
				 rb = rba;
			}else {
				rb = '0'+rba
			}
		}else if(na==1){
			rb+='0';
		}
		stra = ra + rb;
	}else{
		stra = a+'00';
	}
	
	var indexb = b.indexOf(".");
	var lengthb = b.length;
	var strb = b;
	if(indexb != -1){
		nb = lengthb-indexb-1;
		
		var ra = b.substring(0,indexb);
		var rb = b.substring(indexb+1,lengthb);
		
		if(nb>2){
			var rba = rb.substring(0,2);
			var rbb = rb.substring(2,3);
			if(Number(rbb)>=5){
				rba = Number(rba)+1;
			}
			if(rba.length>2){
				rb = '00';
				ra = Number(ra)+1;
			}else if(rba.length==2){
				 rb = rba;
			}else {
				rb = '0'+rba
			}
		}else if(nb==1){
			rb+='0';
		}
		strb = ra + rb;
	}else{
		strb = b+'00';
	}
	
	numbera = Number(stra);
	numberb = Number(strb);
	
	var reduce = numbera-numberb;
	return jQuery.multiply(reduce,0.01);
};